/*
 * @Author: Chili (2239772586@qq.com) 
 * @Date: 2019-06-17 20:19:22 
 * @Last Modified by: Chili (2239772586@qq.com)
 * @Last Modified time: 2019-06-20 09:36:41
 */

let audioIlink = null;

let Voice = (function(_self) {

	//开始
	_self.play = function (src,callback,cancelBack) {
		if ((src.indexOf(".mp3") > -1) || (src.indexOf(".wav") > -1)){
			audioIlink = new Audio();
			audioIlink.src = src;
			audioIlink.play();
			if (callback){
				callback();
			}
			audioIlink.addEventListener('ended', function () {
				if(cancelBack){
					cancelBack();
				}
			}, false);
		}else{
			console.error("未找到语音文件");
		}
	}

	//暂停
	_self.pause = function(){
		audioIlink.pause();
	}

	//继续
	_self.resume = function(){
		audioIlink.play();
	}

	//停止
	_self.cancel = function () {
		if (audioIlink){
			audioIlink.pause();
			audioIlink.currentTime = 0;
			audioIlink = null;
		}
		
	}
	 

 	return _self;
})(window.Voice || {});

